import mockjs from "mockjs"

const { data } = mockjs.mock({
    "data|20": [
        {
            "id|+1": 1001,
            "type|1": ["finish", "undo", "fail"],
            "name": "@cname",
            "goods": ["@cword(2,5)"],
            "time": "@datetime",
            "money|1-100": 100,
        }
    ]
})

export default [
    {
        url: /\/record/,
        method: /post/,
        response: function (option) {
            const newData = []
            option.body.datas.forEach(item => {
                newData.push(item.name)
            })
            data.push({
                id: data[data.length - 1].id + 1,
                type: "undo",
                name: option.body.name,
                time: mockjs.Random.now(),
                money: option.body.money,
                goods: newData
            })
            return {
                code: 0,
                msg: "添加数据成功"
            }
        }
    },
    {
        url: /\/record/,
        method: /get/,
        response: function (option) {
            return {
                code: 0,
                msg: "获取记录列表",
                data: data.filter(item => item.type == option.body.type)
            }
        }
    }
]